package com.company.chu;

public class Sort3 {

    public static void main(String[] args) {
        int[] nums = {2, 0, 2, 1, 1, 0};
        quickSort(0, nums.length - 1, nums);
        for (int n : nums) {
            System.out.print(n + " ");
        }
    }


    /**
     * 快速排序
     *
     * @param low
     * @param high
     * @param nums
     */
    public static void quickSort(int low, int high, int[] nums) {
        if (low > high) {
            return;
        }
        int i = low, j = high;
        int temp = nums[low];
        while (i < j) {
            while (i < j && nums[j] >= temp) {
                j--;
            }
            while (i < j && nums[i] <= temp) {
                i++;
            }
            if (i < j) {
                int t = nums[i];
                nums[i] = nums[j];
                nums[j] = t;
            }
        }
        nums[low] = nums[i];
        nums[i] = temp;
        quickSort(low, i - 1, nums);
        quickSort(i + 1, high, nums);
    }

}
